//
//  YJResultHeaderView.m
//  练习04
//
//  Created by hcios on 2017/7/6.
//  Copyright © 2017年 hcios. All rights reserved.
//

#import "YJResultHeaderView.h"
#import "UIImageView+WebCache.h"

#define FONT_NAME_LTH                   @"FZLanTingHeiS-R-GB"

@implementation YJResultHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupSubViews];
    }
    return self;
}

-(void)setupSubViews{
    //背景
    _backImgView = [[UIImageView alloc] initWithFrame:self.bounds];
    //可以添加手势
    _backImgView.userInteractionEnabled = YES;
    [self addSubview:_backImgView];
    
    //头像
    _userImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, self.frame.size.height - 50, 40, 40)];
    _userImgView.layer.cornerRadius = 20;
    _userImgView.layer.masksToBounds = YES;
    _userImgView.layer.borderWidth = 2;
    _userImgView.userInteractionEnabled = YES;
    _userImgView.layer.borderColor = [UIColor whiteColor].CGColor;
    [_backImgView addSubview:_userImgView];
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickImg)];
    [_userImgView addGestureRecognizer:ges];
    
    //名称
    _nameLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_userImgView.frame), self.frame.size.height - 50, self.frame.size.width, 20)];
    [_nameLab setTextColor:[UIColor whiteColor]];
    [_nameLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    _nameLab.textAlignment = NSTextAlignmentLeft;
    _nameLab.numberOfLines = 0;
    _nameLab.shadowColor = [UIColor grayColor];
    _nameLab.shadowOffset = CGSizeMake(1, 1);
    [_backImgView addSubview:_nameLab];
    
    //日期
    _dayLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_userImgView.frame), CGRectGetMaxY(_nameLab.frame), self.frame.size.width, 20)];
    [_dayLab setTextColor:[UIColor whiteColor]];
    [_dayLab setFont:[UIFont fontWithName:FONT_NAME_LTH size:13]];
    _dayLab.textAlignment = NSTextAlignmentLeft;
    _dayLab.shadowColor = [UIColor grayColor];
    _dayLab.shadowOffset = CGSizeMake(1, 1);
    [_backImgView addSubview:_dayLab];
    
}


-(void)setModel:(YJResultModel *)model{
    _model = model;
    [_backImgView sd_setImageWithURL:[NSURL URLWithString:model.header_front_cover_photo_url] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    [_userImgView sd_setImageWithURL:[NSURL URLWithString:model.user_image] placeholderImage:[UIImage imageNamed:@"zhanWeiTu"]];
    _nameLab.text = model.header_name;
    _dayLab.text = model.header_start_date;
}

-(void)clickImg{
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickUserImg)]) {
        [self.delegate clickUserImg];
    }
}

@end
